<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <title>生产问题处理看板</title>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData()">
    <el-row class="header">
      <el-col :span="6"><img src="../images/aeec_logo.png" height="60" alt="黎阳LOGO" /></el-col>
      <el-col :span="12" class="header-title" id="">{{title}}</el-col>
      <el-col :span="6" class="currentTime">{{currentTime}}</el-col>
    </el-row>
    <div style="padding:10px;">
      <el-form :inline="true" :model="queryInfo" :label-position="'left'">
        <el-form-item label="分厂:">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择" filterable @change="factorySelectChange">
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="工区:">
          <el-select v-model="queryInfo.workcenterid" placeholder="请选择" filterable clearable
            @change="workcenterSelectChange">
            <el-option v-for="w in workcenterList" :key="w.workcenterid" :label="w.workcentername"
              :value="w.workcenterid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="状态:">
          <el-select v-model="queryInfo.status" filterable style="width:100px;">
            <el-option :key="'未处理'" :label="'未处理'" :value="'1'"></el-option>
            <el-option :key="'处理中'" :label="'处理中'" :value="'2'"></el-option>
            <el-option :key="'处理完'" :label="'处理完'" :value="'3'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item style="height:40px;">
          <el-button type="primary" @click="handleBtnSearch" icon="el-icon-search" size="small">查询</el-button>
          <el-button type="primary" @click="exportExcel" icon="el-icon-download" size="small">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
        element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
        <el-table-column type="index" width="40"></el-table-column>
        <el-table-column label="问题描述" prop="description" show-overflow-tooltip></el-table-column>
        <el-table-column label="责任单位" prop="responsibilityworkcenter" width="100" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="责任人" prop="responsibilityemployeename" width="60" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="问题类型" prop="ufccontent" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="处理意见" prop="ufcresult" width="200" show-overflow-tooltip></el-table-column>
        <el-table-column label="提出单位" prop="createworkcenter" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="提出人" prop="createemployee" width="60" show-overflow-tooltip></el-table-column>
        <el-table-column label="提出时间" prop="ufccreatedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="临超期时间" prop="linjinqidate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="要求完成时间" prop="needcompletedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="状态" prop="ufcstatus" width="80" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag v-if="scope.row.ufcstatus === '未处理'" type="danger">{{scope.row.ufcstatus}}</el-tag>
            <el-tag v-else-if="scope.row.ufcstatus === '处理中'" type="warning">{{scope.row.ufcstatus}}</el-tag>
            <el-tag v-else type="success">{{scope.row.ufcstatus}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="需求程度" prop="priority" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column label="超期时间" prop="delaytime" width="160" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-popover trigger="click" placement="top">
              <p>
                超期时间: 当前时间 - 问题提出时间 - 需求程度
              </p>
              <p>
                需求程度: 一般（3天）、急（1天）、紧急（4小时）、特急（1小时）
              </p>
              <div slot="reference">
                <i class="el-icon-info" style="margin-right: 5px;"></i>{{scope.row.delaytime}}
              </div>
            </el-popover>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
        :page-sizes="[12,50,100]" :page-size="pageSize" layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>
  <script type="module">
    import { getParams, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { getUserInfo, getFactory, getWorkcenterList } from '../Scripts/hooks/fetchAPI.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    const app = new Vue({
      el: '#app',
      data: {
        splitDate,
        currentTime: '',// 当前时间
        queryInfo: {
          factoryid: '',
          factoryname: '',
          workcenterid: '',
          workcentername: '',
          status: ''
        },
        currentPage: 1,//当前页
        pageSize: 12, //每页显示条数
        total: 0,// 总条数 
        loading: false,
        loadingText: '拼命加载中',
        dataList: [],
        factoryList: [],
        workcenterList: [],
        userInfo: {}
      },
      methods: {
        async factorySelectChange(val) {
          this.queryInfo.workcenterid = '';
          this.queryInfo.workcentername = '';
          if (val) {
            this.queryInfo.factoryname = this.factoryList.filter(item => item.factoryid === val)[0].factoryname;
            this.workcenterList = await getWorkcenterList({ factoryid: val || this.queryInfo.factoryid });
          }
        },
        workcenterSelectChange(val) {
          this.queryInfo.workcentername = ''
          if (val) {
            const workcentername = this.workcenterList.filter(item => item.workcenterid == this.queryInfo.workcenterid)[0].workcentername
            this.queryInfo.workcentername = workcentername
          }
        },
        // 查询数据
        async getData(currentpage) {
          this.loading = true;
          this.loadingText = '数据查询中...';
          const { data: { data, meta, total } } = await axios({
            method: 'post',
            url: '../handler/board/MfgProblemDashBoard.ashx?action=getData',
            data: {
              type: 'getData',
              ...this.queryInfo,
              currentPage: this.currentPage,
              pageSize: this.pageSize
            }
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.dataList = data;
          this.total = total;
        },
        //监听 currentpage 改变
        handleCurrentChange(newPage) {
          this.currentPage = newPage;
          this.getData();
        },
        //监听 pagezie 改变
        handleSizeChange(newSize) {
          this.pageSize = newSize;
          this.getData();
        },
        handleBtnSearch() {
          this.currentPage = 1
          this.getData()
        },
        exportExcel() {
          const config = {
            url: '../handler/board/MfgProblemDashBoard.ashx?action=exportData',
            data: {
              type: 'exportData',
              ...this.queryInfo,
              title: this.title
            }
          }
          exportExcelData(config, this);
        }
      },
      async mounted() {
        let incrementNumber = () => {
          setTimeout(incrementNumber, 500);
          this.currentTime = dayjs().format('YYYY年MM月DD日  HH:mm:ss');
        }
        setTimeout(incrementNumber, 500);
        this.userInfo = await getUserInfo({ employeeid: getParams("uid") });
        this.factoryList = await getFactory();//查询分厂列表

        if (this.userInfo.factoryid && this.factoryList.some(item => item.factoryid === this.userInfo.factoryid)) {
          const { factoryid, factoryname } = this.userInfo;
          this.queryInfo.factoryid = factoryid;
          this.queryInfo.factoryname = factoryname;
        } else {
          this.queryInfo.factoryid = this.factoryList[0].factoryid;
          this.queryInfo.factoryname = this.factoryList[0].factoryname;
        }

        this.workcenterList = await getWorkcenterList({ factoryid: this.queryInfo.factoryid || this.queryInfo.factoryid });
        if (this.userInfo.workcenterid && this.workcenterList.some(item => item.workcenterid === this.userInfo.workcenterid)) {
          const { workcenterid, workcentername } = this.userInfo;
          this.queryInfo.workcenterid = workcenterid;
          this.queryInfo.workcentername = workcentername;
        }
        document.title = this.title;
        this.getData();
      },
      computed: {
        title() { return `${this.queryInfo.factoryname}-${this.queryInfo.workcentername}-生产问题处理看板`; }
      }
    })
  </script>
</body>

</html>